package com.qf.compusdemo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.compusdemo.dao.FbDao;
import com.qf.compusdemo.entity.Fb;
import com.qf.compusdemo.entity.Fb;
import com.qf.compusdemo.service.FbService;
import com.qf.compusdemo.vo.MessageVo;
import com.qf.compusdemo.vo.Ppage;
import com.qf.compusdemo.vo.tableVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/fb")
public class FbController {

    @Autowired
    private FbService fbService;
    @Autowired
    private FbDao fbd;

    @RequestMapping("/alls")
    @ResponseBody
    public tableVo<Fb> test0(Fb bb,Ppage page){
        System.out.println(page);
        System.out.println(bb);
        Page<Fb> pp=new Page<>(page.getPage(),page.getLimit());
        IPage<Fb> ipage=fbService.getAllBullet(pp,bb);
        tableVo<Fb> table=new tableVo<>();
        table.setCode("0");
        table.setMsg("ok");
        table.setData(ipage.getRecords());
        table.setCount(ipage.getTotal());
        System.out.println(table);

        return table;
    }


    @RequestMapping("del")
    @ResponseBody
    public MessageVo test1(Integer[] ids){
        List lists=java.util.Arrays.asList(ids);
        int a=fbd.deleteBatchIds(lists);
        MessageVo message=new MessageVo();
        message.setStatus(a>0?true:false);
        message.setMessage(a>0?"success":"fail");
        return message;
    }

    @RequestMapping("/adddb")
    @ResponseBody
    public MessageVo test2(Integer[] ids){
        List lists=java.util.Arrays.asList(ids);
        int a=fbService.adddb(ids);
        MessageVo message=new MessageVo();
        message.setStatus(a>0?true:false);
        message.setMessage(a>0?"success":"fail");
        return message;

    }


}
